package org.example;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        String[] strings = {args[1], args[2]};
        if ("location".equals(args[0])) {
            Location.main(strings);
        } else if ("trip".equals(args[0])) {
            Trip.main(strings);
        }
    }


    public static class DataPreProcessMapper extends Mapper<LongWritable, Text, Text, NullWritable> {
        @Override
        protected void map(LongWritable key, Text value, Context context)
                throws IOException, InterruptedException {
            String line = value.toString();
            // 跳过标题行
            if (line.contains("VendorID")) {
                System.err.println("跳过标题行");
                return;
            }

            String[] fields = line.split(",");

            String pickupDatetime = fields[1];
            String[] split = pickupDatetime.split("\\s+");
            String[] arr = split[0].split("-");
            String hour = split[1].split(":")[0];

            context.write(new Text(line + String.format(",%s,%s,%s,%s", arr[0], arr[1], arr[2], hour)), NullWritable.get());
        }
    }
}